Program instantly closing [migrated]

Posted by Ben Clayton on Programmers See other posts from Programmers or by Ben Clayton
Published on 2013-10-29T14:47:04Z Indexed on 2013/10/29 16:11 UTC
Read the original article Hit count: 273

Filed under:

I made this program and when I compiled it there were no errors but the program just instantly closed, any answers would be appreciated.

#include <iostream> //Main commands
#include <string> // String commands
#include <windows.h> // Sleep
using namespace std;

int main ()
{
    //Declaring variables
    float a; 
    bool end; 
    std::string input;

    end = false; // Making sure program doesn't end instantly

    cout << "Enter start then the number you want to count down from." << ".\n";

    while (end = false){
        cin >> input;
        cout << ".\n";

        if (input.find("end") != std::string::npos) // Ends the program if user types end
            end = true;

        else if (input.find("start" || /* || is or operator*/ "restart") != std::string::npos) // Sets up the countdown timer if the user types start 
        {
            cin >> a;
            cout << ".\n";

            while (a>0){
                Sleep(100);

                a = a - 0.1;

                cout << a << ".\n";
            }

            cout << "Finished! Enter restart and then another number, or enter end to close the program" << ".\n";
         }

        else // Tells user to start program
        cout << "Enter start";

    }

    return 0; // Ends program when (end = true)

}

© Programmers or respective owner

Related posts about c++